package jwt

import (
	"BaseApi/common/global"
	"fmt"
	"github.com/dgrijalva/jwt-go"
	"time"
)

type CustomClaims struct {
	ID          uint
	NickName    string
	AuthorityId uint
	jwt.StandardClaims
}

// 生成token封装
func CreateToken(userId uint, userName string) string {
	j := NewJWT(global.GlobalConfig.JwtInfo.JwtKey)

	//定义token结构体
	claims := CustomClaims{
		ID:          userId,
		NickName:    userName,
		AuthorityId: 1,
		StandardClaims: jwt.StandardClaims{
			NotBefore: time.Now().Unix(),               //签名的生效时间
			ExpiresAt: time.Now().Unix() + 60*60*24*30, //30天过期
			Issuer:    "MxShop",
		},
	}
	//调用生成token方法
	token, err := j.CreateToken(claims)
	if err == nil {
		fmt.Println("xxxx")
	}
	return token
}
